/*
 * @Author: your name
 * @Date: 2021-10-19 14:34:53
 * @LastEditTime: 2021-12-30 18:47:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jingfeng-web\src\permission.js
 */
import router from './router'
import store from './store'
// import { resetRouter } from '@/router'
// import { getToken } from '@/utils/auth' // get token from cookie
import { getCurrentModuleListPermission, getCurrentModuleBtnPermission } from './utils/btnPermission' // 按钮权限操作
const MENULIST = {
    menulist: [
        {
            id: 'M1102',
            name: '我的待办',
            path: '/myWait',
            icon: ' ',
            key: false
        },
        // {
        //     id: 'M1101',
        //     name: '看板',
        //     path: '/overView',
        //     icon: ' ',
        //     key: false
        // },

        {
            id: 'M1103',
            name: '反馈总览',
            path: '/feedBack',
            icon: '',
            key: false
        },
        {
            id: 'M1104',
            name: '任务总览',
            path: '/task',
            icon: '',
            key: false
        },

        {
            id: 'M1106',
            name: '系统设置',
            path: '/systemSetting',
            icon: '',
            key: true,
            children: [
                {
                    id: 'M1106',
                    name: '流程节点设置',
                    path: '/systemSetting/column',
                    icon: '',
                    children: []
                },
                {
                    id: 'M1106',
                    name: '自定义设置',
                    path: '/systemSetting/marketingProStatus',
                    icon: '',
                    children: []
                },
                {
                    id: 'M1106',
                    name: '消息设置',
                    path: '/systemSetting/messageSettings',
                    icon: '',
                    children: []
                },
                {
                    id: 'M1106',

                    name: '产品权限设置',
                    path: '/systemSetting/productSettings',
                    icon: '',
                    children: []
                },
                {
                    id: 'M1106',
                    name: '邮件设置',
                    path: '/systemSetting/emileSettings',
                    icon: '',
                    children: []
                },
                {
                    id: 'M1106',
                    name: '超期设置',
                    path: '/systemSetting/overTineMeeting',
                    icon: '',
                    children: []
                },
                {
                    id: 'M1106',

                    name: '公告设置',
                    path: '/systemSetting/noticeSetting',
                    icon: '',
                    children: []
                }
            ]
        },
        {
            id: 'M1105',
            name: '数据统计',
            path: '/dataStatistics',
            icon: '',
            key: false
        },
        {
            id: 'M1107',
            name: '超期会议',
            path: '/delateMeeting',
            icon: '',
            key: false
        },
        {
            id: 'M1108',
            name: '反馈详情',
            path: '/Details',
            icon: '',
            key: false,
            isShows: false
        },
        {
            id: 'M1108',
            name: '反馈详情',
            path: '/linkDetail',
            icon: '',
            key: false,
            isShows: false
        },
        {
            id: 'M1109',
            name: '任务详情',
            path: '/taskDetail',
            icon: '',
            key: false,
            isShows: false
        },
        {
            id: 'M1110',
            name: '数据统计详情',
            path: '/dataStaticDetail',
            icon: '',
            key: false,
            isShows: false
        },
        {
            id: 'M1111',
            name: '超期反馈会议详情',
            path: '/mettingDetail',
            icon: '',
            key: false,
            isShows: false
        },
        {
            id: 'M1112',
            name: '我的发起',
            path: '/mySponsor',
            icon: 'el-icon-s-flag',
            key: false
        }

    ]
}
router.beforeEach((to, from, next) => {
    console.log(to)
    const permissonTree = JSON.parse(sessionStorage.getItem('USERINFO'))
    if (permissonTree) {
        const res = getCurrentModuleListPermission(MENULIST.menulist, permissonTree.permissonTree)
        sessionStorage.setItem('MENULIST', JSON.stringify(res))
        const btnList = getCurrentModuleBtnPermission(to.path, res)
        sessionStorage.setItem('BUTTONLIST', JSON.stringify(btnList))
        store.dispatch('permission/generateRoutes', ['admin'])
        store.dispatch('permission/addButtonList', to)
        // if (!JSON.parse(sessionStorage.getItem('userData'))) {
        store.dispatch('user/getuserId')
        // }
    }
    store.dispatch('situation/setCommentText')
    next()
})

